package team.pra.manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.pra.manager.common.ManagerResult;
import team.pra.manager.common.PageHelper;
import team.pra.manager.mapper.FloorMapper;
import team.pra.manager.mapper.RoomMapper;
import team.pra.manager.pojo.Floor;
import team.pra.manager.pojo.Room;
import team.pra.manager.service.FloorService;

import java.util.List;
@Service
public class FloorServiceImpl implements FloorService {
    @Autowired(required = false)
    private FloorMapper floorMapper;
    @Autowired(required = false)
    private RoomMapper roomMapper;
    @Override
    public void findFloorByCondition(PageHelper<Floor> pageHelper) {
        List<Floor> floors = floorMapper.findFloorByCondition(pageHelper);
        pageHelper.setData(floors);
        pageHelper.setRecordsFiltered(floorMapper.countFilteredFloor(pageHelper));
        pageHelper.setRecordsTotal(floorMapper.countAllFloor());
    }

    @Override
    public List<Floor> findAllFloor() {
        return floorMapper.findAllFloor();
    }

    @Override
    public ManagerResult deleteFloorType(Integer id) {
        List<Room> rooms = roomMapper.findRoomByFloorId(id);
        return ManagerResult.ok(floorMapper.deleteFloor(id));
    }

    @Override
    public ManagerResult updateFloorType(Floor floor) {
        return ManagerResult.ok(floorMapper.updateFloor(floor));
    }

    @Override
    public ManagerResult insertFloorType(Floor floor) {
        return ManagerResult.ok(floorMapper.insertFloor(floor));
    }
}
